import VueRouter from "vue-router"
import Home from '../pages/Home.vue'
import About from '../pages/About.vue'
import News from '../pages/News.vue'
import Message from '../pages/Message.vue'
import Detail from '../pages/Detail.vue'
const router = new VueRouter({
    mode:'history',//hash history
    routes:[
        {
            path:'/home',
            name:'zhuye',
            component:Home,
            meta:{title:'主页'},
            children:[
                {
                    name:'xinwen',
                    path:'news',
                    component:News,
                    meta:{isAuth:true,title:'新闻'},
                    // beforeEnter:(to,from,next)=>{
                    //     //独享前置路由守卫 独享的只有前置路由守卫
                    //     if(to.meta.isAuth){
                    //         if(localStorage.getItem("school")==='atguigu'){
                    //             next()
                    //         }else{
                    //             alert("学校名不对，无权查看")
                    //         }
                    //     }else{
                    //         next()
                    //     }
                    // }
                },
                {
                    name:'xiaoxi',
                    path:'message',
                    component:Message,
                    meta:{isAuth:true,title:'消息'},
                    children:[
                        // {
                        //     path:'detail',
                        //     name:'xiangqing',
                        //     component:Detail
                        // }
                        {
                            // path:'detail/:id/:title',
                            path:'detail',
                            name:'xiangqing',
                            component:Detail,
                            meta:{title:'详情'},
                            // 会把props对象里面的key-value以props方式传递给detail
                            // props:{a:1,b:2}
                            //会把组件内收到的所有params参数以props方式传递给detail
                            // props:true
                            //第三者，函数方式
                            props($route){
                                return {
                                    id:$route.query.id,
                                    title:$route.query.title
                                }
                            }
                        }
                    ]
                }
            ]
        },
        {
            path:'/about',
            component:About,
            meta:{isAuth:true,title:'关于'},
        }
    ]
})
//全局前置路由守卫，初始化以及每次路由切换之前调用
// router.beforeEach((to,from,next)=>{
//     // console.log('@',to,from)
//     // if(to.path ==='/home/news' || to.path ==='/home/message'){
//     if(to.meta.isAuth){
//         if(localStorage.getItem("school")==='atguigu'){
//             next()
//         }else{
//             alert("学校名不对，无权查看")
//         }
//     }else{
//         next()
//     }
// })
//全局后置路由守卫，初始化以及每次路由切换之后调用
// router.afterEach((to,from)=>{
//     // console.log('afterEach',to,from)
//     document.title = to.meta.title || '硅谷系统'
// })
export default router